package xyz.bali16.module.sign.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.base.Preconditions;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import xyz.bali16.module.sign.entity.SignAttendance;
import xyz.bali16.module.sign.entity.SignEvent;
import xyz.bali16.module.sign.mapper.SignAttendanceMapper;
import xyz.bali16.module.sign.mapper.SignEventMapper;
import xyz.bali16.module.sign.model.SignEventAddParam;
import xyz.bali16.module.sign.model.SignEventPageParam;
import xyz.bali16.module.sign.model.SignEventUpdateParam;
import xyz.bali16.module.sign.service.SignEventService;

/**
 * @author bali2 on 9/3/2023.
 * @version 1.0
 */
@Service
public class SignEventServiceImpl extends ServiceImpl<SignEventMapper, SignEvent> implements SignEventService {
    private final SignEventMapper signEventMapper;

    public SignEventServiceImpl(SignEventMapper signEventMapper) {
        this.signEventMapper = signEventMapper;
    }

    @Override
    public IPage<SignEvent> getPage(SignEventPageParam param) {
        IPage<?> page = new Page<>(param.getCurrent(), param.getSize());
        return this.baseMapper.getPage(page, param.getEventName());
    }

    @Override
    public void addSignEvent(SignEventAddParam param) throws Exception {
        Preconditions.checkNotNull(param, "SignEventAddParam 参数不能为为空");
        SignEvent sign = new SignEvent();
        BeanUtils.copyProperties(param, sign);
        System.out.println(sign);
        save(sign);
    }

    @Override
    public void updateSignEvent(SignEventUpdateParam param) throws Exception {
        Preconditions.checkNotNull(param, "SignEventAddParam 参数不能为为空");
        SignEvent sign = new SignEvent();
        BeanUtils.copyProperties(param, sign);
        updateById(sign);
    }



    @Override
    public void delete(String signId) throws Exception {
        if (signId == null) {
            return;
        }
        removeById(signId);

    }
}
